import 'dart:async';
import 'package:get/get.dart';
import 'package:flutter_base/base/controller/base_controller.dart';
import 'package:flutter_base/config/app_config.dart';
import 'package:flutter_base/config/app_routes.dart';
import 'package:flutter_base/user/app_user_manager.dart';

class SplashLogic extends BaseController {
  String version = '';
  Timer? _timer;

  @override
  void onInit() {
    super.onInit();
    version = AppConfig.version;
  }

  @override
  void onReady() {
    super.onReady();
    // 延迟2秒后检查登录状态并跳转
    _timer = Timer(const Duration(seconds: 2), () {
      // 检查是否有登录状态
      if (AppUserManager().isLogin) {
        Get.offAllNamed(AppRoutes.main);
      } else {
        Get.offAllNamed(AppRoutes.login);
      }
    });
  }

  @override
  void onClose() {
    _timer?.cancel();
    super.onClose();
  }
}
